package com.clouddisk.file.publisher;

import com.clouddisk.file.observer.FileOperationEvent;
import com.clouddisk.file.observer.FileOperationListener;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
@RequiredArgsConstructor
public class FileOperationPublisher {

    private final List<FileOperationListener> listeners;
    private final ExecutorService executorService = Executors.newFixedThreadPool(5);

    /**
     * 发布文件操作事件
     */
    public void publishEvent(FileOperationEvent event) {
        // 异步通知所有监听器
        listeners.forEach(listener -> 
            executorService.submit(() -> listener.onFileOperation(event))
        );
    }
} 